// Declare all the functions we will need

function getAppletCode(fileName, filePath, ftpDir, ftpAddress, 
		ftpUsername, ftpPassword) {
	var appletHtml = '<applet code="com.oxxo.gallery.ftp.FtpUploadApplet" width="250" ' +
		'height="100" archive="FtpUploadApplet.jar, lib/commons-net-ftp-2.0.jar">' +
		'<param name="localFile" value="'+ localFile +'" />' +
		'<param name="remoteFile" value="'+ remoteFile +'" />' +
		'<param name="ftpDir" value="'+ ftpDir +'" />' +
		'<param name="ftpAddress" value="'+ ftpAddress +'" />' +
		'<param name="ftpUsername" value="'+ ftpUsername +'" />' +
		'<param name="ftpPassword" value="'+ ftpPassword +'" />' +
		'<param name="redirectUrl" value="'+ redirectUrl +'" />' +
		'</applet>';
	
	return appletHtml;
}

function showApplet() {
	$("btnUpload").addEvent("click", function() {
		$("ftpUploadAppletDiv").fade("out");
		var fileName = $("browseFile").getProperty("value");
		var filePathNameArray = fileName.split("\\");
		fileName = filePathNameArray.pop();
		var filePath = filePathNameArray.join("\\");
		var ftpDir = "/src/144";
		var ftpAddress = "fcogal02";
		var ftpUsername = "gallery";
		var ftpPassword = "*OXXO*80";
		var appletCode = getAppletCode(fileName, filePath, ftpDir, ftpAddress, ftpUsername, ftpPassword)
		$("ftpUploadAppletDiv").setProperty("html", appletCode);
		$("ftpUploadAppletDiv").fade("in");
	});
}


// Here we declare function for MooTools as soon as the dom is ready
window.addEvent("domready", showApplet);